package com.lwz.laboratory.controller;

import com.lwz.laboratory.dao.RepairMapper;
import com.lwz.laboratory.entity.Archivses;
import com.lwz.laboratory.entity.Laboratory;
import com.lwz.laboratory.entity.Repair;
import com.lwz.laboratory.entity.Technician;
import com.lwz.laboratory.service.ArchivsesService;
import com.lwz.laboratory.service.LaboratoryService;
import com.lwz.laboratory.service.RepairService;
import com.lwz.laboratory.service.TechnicianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
public class  RepairController {
    @Autowired
    RepairService repairService;
    @Autowired
    TechnicianService technicianService;

    @Autowired
    ArchivsesService archivsesService;

    @Autowired
    LaboratoryService laboratoryService;

    @GetMapping("/exportPdf/{id}")
    public void exportPdf(@PathVariable("id") Integer id, HttpServletResponse response){
         repairService.exportPdf(response,id);
    }
//查看技术员专有实验室
    @RequestMapping("/findallrepair/")
    public String findmyrepair(String technician, Model model){

        System.out.println(technician);
        List<Laboratory> list= laboratoryService.getAlllabbyth(technician);
        System.out.println(list);
        model.addAttribute("laboratorylist",list);
        return "repair/repair_checklab";

    }

    //个人报修列表
    @RequestMapping("/repairone/")
    public String onerepair(String applicant,Model model){
        List<Repair> repair =repairService.selectByperson(applicant);

        model.addAttribute("repairs",repair);

        return "repair/repair_onelist";
    }

    //查看实验室报销信息
    @RequestMapping("/lookrepair")
    public String lookrepair(String laboratory,Model model){
        List<Repair> repair =repairService.findall(laboratory);

        model.addAttribute("repairs",repair);

        return "repair/repair_list";
    }


//报修界面
    @RequestMapping("/toaddrepair")
    public String toaddrepair(){
        return "repair/repaird_add";
    }
//报修
    @RequestMapping("/repairsave")
    public String addrepair(String person,String stuid,Repair repair,Model model){
        System.out.println(person);
        System.out.println(stuid);
        //通过工号把所示实验室查询
        Archivses archivses =archivsesService.selectBystuid(stuid);
        repair.setLaboratory(archivses.getLaboratory());
        repairService.addrepair(repair);
        return onerepair(person,model);
    }



}
